package com.houtai.controller.activity.works;


import com.houtai.authority.Authority;
import com.houtai.authority.AuthorityType;
import com.houtai.base.RetInfo;
import com.houtai.bean.TsJzAdmin;
import com.houtai.bean.dto.activity.works.ActivityWorksListDto;
import com.houtai.bean.dto.activity.works.TdActivityWorksListDto;
import com.houtai.bean.vo.activity.works.TdActivityWorksDetail;
import com.houtai.service.activity.works.ActivityWorksService;
import com.houtai.service.dict.DictService;
import com.houtai.service.funcion.FuncionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;


@Controller
@RequestMapping(value = {"v5"})
public class ActivityWorksController {


    @Resource
    private ActivityWorksService activityWorksService;
    @Resource
    private DictService dictService;

    @Autowired
    private RedisTemplate redisTemplate;
    @Resource
    private FuncionService funcionService;
    /**
     * @Purpose  查找活动作品列表
     * @param
     * @version  3.4.0
     * @author   lizhun
     * @time     2018-07-10
     * @return   ModelAndView
     */
    @Authority(AuthorityType.Login)
    @RequestMapping(value = "/activity/works/list")
    public ModelAndView comments(HttpServletRequest request,TdActivityWorksListDto dto) {
        ModelAndView mv = new ModelAndView("activity/works/list");
        mv.addObject("token", request.getParameter("token"));
        mv.addObject("father_id", request.getParameter("father_id"));
        TsJzAdmin tsJzAdmin = (TsJzAdmin) redisTemplate.opsForValue().get(request.getParameter("token")) ;
        mv.addObject("funcions", funcionService.findSonFuncion(tsJzAdmin, Integer.valueOf(request.getParameter("father_id"))));
        mv.addObject("dicts", dictService.findTsJzDict("works_type"));
        mv.addObject("retInfo", activityWorksService.commentsList(request, dto));
        return mv;
    }
    /**
     * @Purpose  查找活动作品列表
     * @param
     * @version  3.4.0
     * @author   lizhun
     * @time     2018-07-10
     * @return   ModelAndView
     */
    @Authority(AuthorityType.Login)
    @RequestMapping(value = "/activity/works")
    public ModelAndView works(HttpServletRequest request,ActivityWorksListDto dto) {
        ModelAndView mv = new ModelAndView("activity/works_list");
        mv.addObject("token", request.getParameter("token"));
        mv.addObject("dicts", dictService.findTsJzDict("works_type"));
        mv.addObject("retInfo", activityWorksService.activityWorksList(request, dto));
        return mv;
    }
    /**
     * @Purpose  跳转到作品详情
     * @version  1.0
     * @author   lizhun
     * @param    request
     * @return   RetInfo
     */
    @RequestMapping(value="/activity/works/content")
    public ModelAndView index(HttpServletRequest request, Integer works_id){
        ModelAndView mv = new ModelAndView("activity/works/content");
        TdActivityWorksDetail detail = activityWorksService.findTdCourseDetail(works_id);
        mv.addObject("token", request.getParameter("token"));
        mv.addObject("detail", detail);

        return mv;
    }
    /**
     * @Purpose   更新作品状态
     * @param     works_id
     * @version   1.0
     * @author    李准
     * @time      2017-08-19
     * @return    RetInfo
     */
    @RequestMapping(value = "/activity/works/update/state", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    @Authority(AuthorityType.Login)
    public RetInfo valid(Integer works_id, Integer state, HttpServletRequest request) {

        return activityWorksService.updateActivityWorksState(works_id, state, request);
    }
}
